package com.iot08.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iot08.api.annotation.CheckAppSign;
import com.iot08.api.config.redis.RedisFilterService;
import com.iot08.api.controller.base.BaseController;
import com.iot08.api.service.*;
import com.iot08.api.service.supplement.HealthService;
import com.iot08.api.vo.request.base.BaseAccountReqVO;
import com.iot08.common.entity.app.Device;
import com.iot08.common.utils.DateUtil;
import com.iot08.common.utils.response.ResponseMap;
import com.iot08.api.vo.request.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @version 1.0
 * @Description: 设备相关接口
 * @time: 2020/11/23 9:16
 * @author: Rock
 */
@Slf4j
@RestController
@RequestMapping("getway/devices")
public class DeviceController extends BaseController {

    @Resource
    private DeviceService deviceService;
    @Resource
    private PpChatGroupService ppChatGroupService;
    @Resource
    private HealthService healthService;

    @Resource
    private RedisFilterService redisFilterService;

    @Resource
    private DeviceSedentaryService deviceSedentaryService;

    @Resource
    private DeviceCmsgService deviceCmsgService;
    @Resource
    private DeviceSanWordService deviceSanWordService;

    @Resource
    private DeviceAppRecordService deviceAppRecordService;

    @Resource
    private ScreensaverLibraryService screensaverLibraryService;

    @Resource
    private WechatContactService wechatContactService;

    /**
     * 查询设备基本信息
     *
     * @param imei
     * @time: 2020/11/30 16:43
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/{imei}")
    public ResponseMap getInfo(@PathVariable("imei") String imei) {
        return deviceService.getInfo(imei);
    }

    /**
     * 修改设备信息
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/11/30 18:34
     * @author: Rock
     * @version 1.0
     */
    @PatchMapping("/{imei}")
    public ResponseMap updateInfo(@Validated DeviceUpdateInfoReqVO vo, BindingResult bindingResult,
                                  @PathVariable("imei") String imei, MultipartFile image) throws IOException {
        return deviceService.updateInfo(imei, vo, image);
    }

    @PostMapping("/{imei}/update")
    public ResponseMap updateInfo_A(@Validated DeviceUpdateInfoReqVO vo, BindingResult bindingResult,
                                  @PathVariable("imei") String imei, MultipartFile image) throws IOException {
        return deviceService.updateInfo(imei, vo, image);
    }

    /**
     * @description 搜索设备WIFI信息
     * @author cwj
     * @param [imei]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/18 16:56
     **/
    @PostMapping("/{imei}/wifi/search")
    public ResponseMap searchWifiInfo(@PathVariable("imei") String imei,BaseAccountReqVO vo){
        return deviceService.searchWifiInfo(imei,vo);
    }
    
    /**
     * 查询设备设置的连接WIFI信息
     *
     * @param imei
     * @time: 2020/12/2 10:57
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/{imei}/wifi")
    public ResponseMap getWifiInfo(@PathVariable("imei") String imei,@Validated BaseAccountReqVO vo) {
        return deviceService.getWifiInfo(imei);
    }

    /**
     * 设置设备WIFI
     *
     * @param imei
     * @param vo
     * @time: 2020/12/3 15:22
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{imei}/wifi")
    public ResponseMap settingWifiInfo(@PathVariable("imei") String imei, @Validated DeviceUpdateWifiInfoReqVO vo) {
        return deviceService.settingWifiInfo(imei, vo);
    }

   /* @PostMapping("/{imei}/wifi/add")
    public ResponseMap addWifiInfo(@PathVariable("imei") String imei, @Validated DeviceUpdateWifiInfoReqVO vo) {
        return deviceService.addWifiInfo(imei, vo);
    }*/

    @PostMapping("/{imei}/wifi/edit")
    public ResponseMap editWifiInfo(@PathVariable("imei") String imei, @Validated DeviceUpdateWifiInfoReqVO vo) {
        return deviceService.editWifiInfo(vo);
    }

    /**
     * @description 删除设备的wifi
     * @author cwj
     * @param [imei, vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/19 17:37
     **/
    @PostMapping("/{imei}/wifi/del")
    public ResponseMap delWifiInfo(@PathVariable("imei") String imei, @Validated WifiInfoReqVO vo) {
        return deviceService.delWifiInfo(imei, vo);
    }
    
    /**
     * @description 查询当前设备连接的wifi
     * @author cwj
     * @param []
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/20 9:46
     **/
    @PostMapping("/{imei}/wifi/cur")
    public ResponseMap queryCurrentWifiInfo(@PathVariable("imei") String imei, @Validated BaseAccountReqVO vo){
        return deviceService.queryCurrentWifiInfo(imei, vo);
    }

    /**
     * 获取家庭成员
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 11:43
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("member")
    public ResponseMap getMember(@Validated ImeiParamReqVO vo, BindingResult bindingResult) {
        return deviceService.getMember(vo);
    }

    /**
     * 添加家庭成员
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 15:50
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("member")
    public ResponseMap addMember(@Validated DeviceAddMemberReqVO vo, BindingResult bindingResult) {
        return deviceService.addMember(vo);
    }

    /**
     * 修改家庭成员
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 15:54
     * @author: Rock
     * @version 1.0
     */
    @PatchMapping("member")
    public ResponseMap updateMember(@Validated DeviceUpdateMemberReqVO vo, BindingResult bindingResult) {
        return deviceService.updateMember(vo);
    }
    @PostMapping("member/update")
    public ResponseMap updateMember_A(@Validated DeviceUpdateMemberReqVO vo, BindingResult bindingResult) {
        return deviceService.updateMember(vo);
    }

    /**
     * 删除家庭成员
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 18:26
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("member")
    public ResponseMap delMember(@Validated DeviceDelMemberReqVO vo, BindingResult bindingResult) {
        return deviceService.delMember(vo);
    }

    /**
     * 获取设备可视频成员列表
     *
     * @param imei
     * @time: 2020/12/2 10:57
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/{imei}/video_user_list")
    public ResponseMap getOpenidList(@PathVariable("imei") String imei) {
        return deviceService.getOpenidList(imei);
    }

    /**
     * 添加设备可视频成员列表
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 2020/12/3 15:22
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{imei}/video_user_list")
    public ResponseMap addOpenidList(@PathVariable("imei") String imei,
                                   @Validated DeviceAddOpenidListReqVO vo, BindingResult bindingResult) {
        return deviceService.addOpenidList(imei, vo);
    }

    /**
     * 删除设备可视频成员列表
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 18:26
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/{imei}/video_user_list")
    public ResponseMap delOpenidList(@PathVariable("imei") String imei,
                                   @Validated DeviceAddOpenidListReqVO vo, BindingResult bindingResult) {
        return deviceService.delOpenidList(imei, vo);
    }

    /**
     * 更新设备可视频成员列表
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/4 9:30
     * @author: Rock
     * @version 1.0
     */
    @PatchMapping("/{imei}/video_user_list")
    public ResponseMap updateOpenidList(@PathVariable("imei") String imei,
                                        @Validated DeviceUpdateOpenidListReqVO vo, BindingResult bindingResult) {
        return deviceService.updateOpenidList(imei, vo);
    }
    @PostMapping("/{imei}/video_user_list/update")
    public ResponseMap updateOpenidList_A(@PathVariable("imei") String imei,
                                        @Validated DeviceUpdateOpenidListReqVO vo, BindingResult bindingResult) {
        return deviceService.updateOpenidList(imei, vo);
    }

    /**
     * 获取设备通讯录
     *
     * @param imei
     * @time: 2020/12/2 10:57
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/{imei}/contact")
    public ResponseMap getContact(@PathVariable("imei") String imei) {
        return deviceService.getContact(imei);
    }

    /**
     * 添加设备通讯录记录
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 2020/12/3 15:22
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{imei}/contact")
    public ResponseMap addContact(@PathVariable("imei") String imei, @Validated DeviceAddContactReqVO vo, MultipartFile image) throws Exception {
        return deviceService.addContact(imei, vo, image);
    }



    /**
     * 修改设备通讯录记录
     * APP将用户信息也在此进行修改, 使用 type 进行区分
     * @param vo
     * @param bindingResult
     * @time: 2022/03/02 9:30
     * @author: Weichao
     * @version 1.0
     */
    @PatchMapping("/{imei}/contact")
    public ResponseMap updateContact(@PathVariable("imei") String imei, @Validated DeviceUpdateContactReqVO vo, MultipartFile image) throws Exception {
        return deviceService.updateContact(imei, vo, image);
    }
    @PostMapping("/{imei}/contact/update")
    public ResponseMap updateContact_A(@PathVariable("imei") String imei, @Validated DeviceUpdateContactReqVO vo, MultipartFile image) throws Exception {
        return deviceService.updateContact(imei, vo, image);
    }


    /**
     * 删除设备通讯录记录，此接口已弃用
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 18:26
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/{imei}/contact")
    public ResponseMap delContact(@PathVariable("imei") String imei, @Validated IdParamReqVO vo) {
        return deviceService.delContact(imei, vo, false);
    }

    /**
     * 添加设备多个通讯录记录
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @param image
     * @time: 2020/12/4 14:53
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{imei}/mancontact_class")
    public ResponseMap addManycontact(@PathVariable("imei") String imei, @Validated DeviceAddManyContactReqVO vo, MultipartFile image) throws Exception {
        return deviceService.addManycontact(imei, vo, image);
    }

    /**
     * 删除多个设备通讯录记录
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 2021/2/7 9:45
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/{imei}/mancontact_class")
    public ResponseMap delManyContact(@PathVariable("imei") String imei, @Validated ContactIdsParamReqVO vo) {
        return deviceService.delManyContact(imei, vo);
    }

    /**
     * 前端 根据 isAddIOTCard==0 的属性 才会调用此接口
     * 把管理者/关注者的 手机号添加至 卡商系统
     * @param imei
     * @param vo
     * @return
     */
    @PostMapping("/{imei}/addMemberToIOTCard")
    public ResponseMap addMemberToIOTCard(@PathVariable("imei") String imei, DeviceUpdateContactReqVO vo) {
        return deviceService.addMemberToIOTCard(imei, vo.getId(), vo.getOpenid());
    }



    /****************************** 安全区域 **********************/
    /**
     * 获取安全区域
     *
     * @param imei
     * @time: 2020/12/2 10:57
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/{imei}/rail")
    public ResponseMap getRail(@PathVariable("imei") String imei) {
        return deviceService.getRail(imei);
    }

    /**
     * 添加安全区域
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 2020/12/3 15:22
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{imei}/rail")
    public ResponseMap addRail(@PathVariable("imei") String imei,
                               @Validated DeviceAddRailReqVO vo, BindingResult bindingResult) {
        return deviceService.addRail(imei, vo);
    }

    /**
     * 更新安全区域
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/4 9:30
     * @author: Rock
     * @version 1.0
     */
    @PatchMapping("/{imei}/rail")
    public ResponseMap updateRail(@PathVariable("imei") String imei,
                                  @Validated DeviceUpdateRailReqVO vo, BindingResult bindingResult) {
        return deviceService.updateRail(imei, vo);
    }
    @PostMapping("/{imei}/rail/update")
    public ResponseMap updateRail_A(@PathVariable("imei") String imei,
                                  @Validated DeviceUpdateRailReqVO vo, BindingResult bindingResult) {
        return deviceService.updateRail(imei, vo);
    }

    /**
     * 删除安全区域
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/2 18:26
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/{imei}/rail")
    public ResponseMap delRail(@PathVariable("imei") String imei,
                               @Validated IdParamReqVO vo, BindingResult bindingResult) {
        return deviceService.delRail(imei, vo);
    }

    /************************* 聊天群组 **********************/

    /**
     * 获取聊天群组
     *
     * @param imei
     * @time: 2020/12/4 18:42
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/{imei}/related-chat-group")
    public ResponseMap getRelatedChatGroup(@PathVariable("imei") String imei) {
        return deviceService.getRelatedChatGroup(imei);
    }

    /**
     * 添加聊天群组
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 2020/12/7 9:45
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/{imei}/related-chat-group")
    public ResponseMap addRelatedChatGroup(@PathVariable("imei") String imei,
                                           @Validated DeviceAddRelatedChatGroupReqVO vo, BindingResult bindingResult) {
        return deviceService.addRelatedChatGroup(imei, vo);
    }

    /**
     * 退出聊天群组
     *
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 2020/12/15 9:35
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/{imei}/related-chat-group")
    public ResponseMap delRelatedChatGroup(@PathVariable("imei") String imei,
                                           @Validated GroupidParamReqVO vo, BindingResult bindingResult) {
        return deviceService.delRelatedChatGroup(imei, vo);
    }

    /************************* 碰碰交友 **********************/

    /**
     * 查询设备的 好友列表
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/17 15:32
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/ppfriends")
    public ResponseMap listFriends(@Validated ImeiParamReqVO vo, BindingResult bindingResult) {
        return ppChatGroupService.listFriends(vo);
    }

    /**
     * 删除设备的好友
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/17 15:33
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/ppfriends")
    public ResponseMap delFriends(@Validated ImeiAndIdsParamReqVO vo, BindingResult bindingResult) {
        return ppChatGroupService.delFriends(vo);
    }

    /************************* 设备导航 **********************/

    /**
     * 获取设备导航的设置
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/17 17:36
     * @author: Rock
     * @version 1.0
     */
    @GetMapping("/navigation")
    public ResponseMap listNavigation(@Validated ImeiParamReqVO vo, BindingResult bindingResult) {
        return deviceService.listNavigation(vo);
    }

    /**
     * 添加设备导航的设置
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/18 11:34
     * @author: Rock
     * @version 1.0
     */
    @PostMapping("/navigation")
    public ResponseMap addNavigation(@Validated AddNavigationReqVO vo, BindingResult bindingResult) {
        return deviceService.addNavigation(vo);
    }

    /**
     * 修改设备导航的设置
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/18 11:52
     * @author: Rock
     * @version 1.0
     */
    @PatchMapping("/navigation")
    public ResponseMap updateNavigation(@Validated UpdateNavigationReqVO vo, BindingResult bindingResult) {
        return deviceService.updateNavigation(vo);
    }
    @PostMapping("/navigation/update")
    public ResponseMap updateNavigation_A(@Validated UpdateNavigationReqVO vo, BindingResult bindingResult) {
        return deviceService.updateNavigation(vo);
    }

    /**
     * 删除设备导航的设置
     *
     * @param vo
     * @param bindingResult
     * @time: 2020/12/18 12:02
     * @author: Rock
     * @version 1.0
     */
    @DeleteMapping("/navigation")
    public ResponseMap delNavigation(@Validated ImeiAndIdsParamReqVO vo, BindingResult bindingResult) {
        return deviceService.delNavigation(vo);
    }

//    /************************* 健康功能(心率/血压/血氧) 统一接口 **********************/
//
//    /**
//     * 健康功能(心率/血压/血氧) 获取数据
//     *
//     * @param imei
//     * @time: 2020/12/4 18:42
//     * @author: Rock
//     * @version 1.0
//     */
//    @GetMapping("/{imei}/healthfunction")
//    public ResponseMap getHealthfunction(@PathVariable("imei") String imei,
//                                         @Validated GetHealthfunctionReqVO vo, BindingResult bindingResult) {
//        return healthService.getHealthfunction(imei, vo);
//    }
//
//    /**
//     * 设置频率(包括立即测量)
//     *
//     * @param imei
//     * @param vo
//     * @param bindingResult
//     * @time: 2020/12/7 9:45
//     * @author: Rock
//     * @version 1.0
//     */
//    @PostMapping("/{imei}/healthfunction")
//    public ResponseMap addHealthfunction(@PathVariable("imei") String imei,
//                                         @Validated AddHealthfunctionReqVO vo, BindingResult bindingResult) {
//        return healthService.addHealthfunction(imei, vo);
//    }
//
//    /**
//     * 根据当前时间查询历史数据 (心率/血压/血氧)
//     *
//     * @param imei
//     * @param vo
//     * @param bindingResult
//     * @time: 2021/3/9 9:29
//     * @author: Rock
//     * @version 1.0
//     */
//    @GetMapping("/{imei}/healthfunction/history")
//    public ResponseMap getHealthfunctionHistory(@PathVariable("imei") String imei,
//                                                @Validated GetHealthfunctionHistoryReqVO vo, BindingResult bindingResult) {
//        return healthService.getHealthfunctionHistory(imei, vo);
//    }
//
//
//    /************************* 健康功能(心率/血压/血氧) 统一接口 **********************/




    /**
     * 查 自动接通状态及成员列表
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 12/13/21 3:56 PM
     * @author: Weichao
     * @version 1.0
     */
    @GetMapping("/{imei}/aso")
    public ResponseMap asoGet(@PathVariable("imei") String imei,
                           @Validated AsoReqVO vo, BindingResult bindingResult) {
        return deviceService.aso(imei, vo);
    }

    /**
     * 改 自动接通状态及成员列表
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 12/13/21 3:56 PM
     * @author: Weichao
     * @version 1.0
     */
    @PostMapping("/{imei}/aso")
    public ResponseMap aso(@PathVariable("imei") String imei, @Validated AsoReqVO vo, BindingResult bindingResult) {
        return deviceService.aso(imei, vo);
    }

    /**
     * 查 久坐提醒
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 12/13/21 3:56 PM
     * @author: Weichao
     * @version 1.0
     */
    @GetMapping("/{imei}/sedentary")
    public ResponseMap sedentaryGet(@PathVariable("imei") String imei, @Validated SedentaryReqVO vo, BindingResult bindingResult) {
        return deviceSedentaryService.sedentary(imei, vo);
    }

    /**
     * 改 久坐提醒
     * @param imei
     * @param vo
     * @param bindingResult
     * @time: 12/13/21 3:56 PM
     * @author: Weichao
     * @version 1.0
     */
    @PostMapping("/{imei}/sedentary")
    public ResponseMap sedentary(@PathVariable("imei") String imei, @Validated SedentaryReqVO vo, BindingResult bindingResult) {
        return deviceSedentaryService.sedentary(imei, vo);
    }

    
    /**
     * @description 查询代收短信
     * @author cwj
     * @param [imei, vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/17 9:25
     **/
   /* @GetMapping("/cmsg/")
    @CheckAppSign
    public ResponseMap cmsgGet(@Validated CmsgReqVO vo) {
        return deviceCmsgService.cmsg(vo.getBodyForm());
    }*/

    /**
     * @description 查询/改/删代收短信
     * @author cwj
     * @param [imei, vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/17 9:21
     **/
    @PostMapping("/cmsg")
    @CheckAppSign
    public ResponseMap cmsg(@Validated @RequestBody CmsgReqVO vo) {
        return deviceCmsgService.cmsg(vo.getBodyForm());
    }


    /**
     * @description 查询上报的话费流量数据
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/29 18:12
     **/
    @PostMapping("/queryPhoneChargeCmsg")
    @CheckAppSign
    public ResponseMap queryPhoneChargeCmsg(@Validated @RequestBody InquirePhoneChargeCmsgReqVo vo) {
        return deviceCmsgService.queryPhoneChargeCmsg(vo.getBodyForm());
    }


    //=====设备OTA升级======
    @GetMapping("/{imei}/remoteUp")
    public ResponseMap remoteUpGet(@PathVariable("imei") String imei,
                                @Validated DeviceRemoeOTAReqVO vo, BindingResult bindingResult) {
        return deviceService.remoteUpGet(imei, vo);
    }

    @PostMapping("/{imei}/remoteUp")
    public ResponseMap remoteUpPost(@PathVariable("imei") String imei,
                                   @Validated DeviceRemoeOTAReqVO vo, BindingResult bindingResult) {
        return deviceService.remoteUpPost(imei, vo);
    }

    @GetMapping("/{imei}/lossDev")
    public ResponseMap lossDevGet(@PathVariable("imei") String imei,
                                  @Validated BaseAccountReqVO vo, BindingResult bindingResult) {
        return deviceService.lossDevGet(imei, vo);
    }

    //=====云生词本=====

    @PostMapping("/{imei}/strangenessword")
    public ResponseMap postStrangenessword(@PathVariable("imei") String imei, SanWordReqVO vo) {
        if(vo.getDelIds() != null){
            deviceSanWordService.delWithIds(vo.getDelIds());
            return ResponseMap.success();
        }else{
            return ResponseMap.fail("miss delIds");
        }

    }

    /**
     * 获取上传词典 的状态 上传了多少个,限制是多少个
     * @param imei
     * @param vo
     * @param bindingResult
     * @return
     */
    @GetMapping("/{imei}/strangenesswordlimit")
    public ResponseMap getStrangenesswordLimit(@PathVariable("imei") String imei,
                                          SanWordReqVO vo, BindingResult bindingResult) {
        JSONObject res = new JSONObject();
        //当天内的时间  yyyyMMddHHmmss ~ yyyyMMddHHmmss

        // 创建一个格式化日期时间的 SimpleDateFormat 对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String todayDateStr = sdf.format(new Date());
        String startDate = todayDateStr+"000000";
        String endDate = todayDateStr+"235959";

        //上传个数
        String todayUpdateCount = redisFilterService.get(deviceSanWordService.deviceSanWordUpdateDayCountKey + imei + "&" + todayDateStr);
        if(todayUpdateCount == null){
            todayUpdateCount = "0";
        }
        log.info("imei:{} vo:{} startDate:{} endDate:{} 今天的上传个数todayUpdateCount:{}", imei, vo, startDate, endDate);

        //上传个数
//        long todayUpdateCount = deviceSanWordService.getCount(imei, startDate, endDate);
        res.put("todayUpdateCount", Integer.valueOf(todayUpdateCount));
        //限制上传的个数
        res.put("limitCount", deviceSanWordService.deviceSanWordUpdateDauLimit);
        res.put("showDes", todayUpdateCount+"/"+deviceSanWordService.deviceSanWordUpdateDauLimit);
        return ResponseMap.success(res);
    }
    
    /***
     * @description 陌生人拦截测试
     * @author cwj
     * @param [imei, vo, bindingResult]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/11/8 17:33
     **/
    @GetMapping("/{imei}/strangenessword")
    public ResponseMap getStrangenessword(@PathVariable("imei") String imei,
                                  SanWordReqVO vo, BindingResult bindingResult) {
        JSONObject res = new JSONObject();

        String dateStr = vo.getDateStr();
        //(默认)0: 只返回日期  1: 指定日期的完整数据
        String startDate = "";
        String endDate = "";
        if (vo.getType() == 0) {
            startDate = "";
            endDate = "";
            JSONObject dateMap = (JSONObject)deviceSanWordService.listData(imei, vo.getType(), startDate, endDate);
            res.put("dateMap", dateMap);
        }else if(vo.getType() == 1){
            //eg: 20230912
            //一天内的时间  yyyyMMddHHmmss ~ yyyyMMddHHmmss
            startDate = dateStr+"000000";
            endDate = dateStr+"235959";
            JSONArray dataList = (JSONArray)deviceSanWordService.listData(imei, vo.getType(), startDate, endDate);
            res.put("dataList", dataList);
        }
        log.info("查生词 imei:{} vo:{} res:{}", imei, vo, res);
        return ResponseMap.success(res);
    }

    /**
     * 查询生词本记录
     * @param imei
     * @param vo
     * @param bindingResult
     * @return
     */
    @GetMapping("/{imei}/cloud/strangenessword")
    public ResponseMap getCloudStrangenessword(@PathVariable("imei") String imei, SanWordReqVO vo, BindingResult bindingResult) {
        JSONObject res = new JSONObject();
//        String dateStr = vo.getDateStr();
//        //eg: 20230912
//        //一天内的时间  yyyyMMddHHmmss ~ yyyyMMddHHmmss
//        String startDate = dateStr+"000000";
//        String endDate = dateStr+"235959";
        JSONArray dataList = (JSONArray)deviceSanWordService.listData(imei, vo.getType(),"","");
        res.put("wordList", dataList);

        String dateStr = DateUtil.dateToStr(new Date(), "yyyyMMdd");
        //今天的 上传个数
        String todayUpdateCount = redisFilterService.get(deviceSanWordService.deviceSanWordUpdateDayCountKey + imei + "&" + dateStr);
        if(todayUpdateCount == null){
            todayUpdateCount = "0";
        }
        res.put("todayNum", Integer.valueOf(todayUpdateCount));

        //统计周
        Long weekUpdateWordWithDev = deviceSanWordService.getWeekUpdateWordWithDev(imei, new Date());
        res.put("weekNum", weekUpdateWordWithDev);
//        Long allWordWithDev = deviceSanWordService.getAllWordWithDev(imei);
        Device device = deviceService.findById(imei);
        if (device != null){
            res.put("allNum", device.getUpdateWordCount());
        }

//        log.info("查生词 imei:{} vo:{} res:{}", imei, vo, res);
        return ResponseMap.success(res);
    }


    /**
     * 查 应用使用记录
     * @param imei
     * @param vo
     * @time: 12/21/23 11:56 AM
     * @author: Weichao
     * @version 1.0
     */
    @GetMapping("/{imei}/appRecord")
    public ResponseMap appRecordGet(@PathVariable("imei") String imei, @Validated AppRecordReqVO vo) {
        return deviceAppRecordService.recordData(imei, vo);
    }

    /**
     * 删 应用使用记录
     * @param imei
     * @param vo
     * @time: 12/21/23 11:56 AM
     * @author: Weichao
     * @version 1.0
     */
    @PostMapping("/{imei}/appRecord")
    public ResponseMap appRecord(@PathVariable("imei") String imei, @Validated AppRecordReqVO vo) {
        return deviceAppRecordService.recordData(imei, vo);
    }

    /**
     * @description 查询专属屏保的图库
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/21 10:39
     **/
    @GetMapping("/{imei}/queryScreensavers")
    public ResponseMap queryScreensaverLibrary(@PathVariable("imei") String imei,@Validated BaseAccountReqVO vo){
        return screensaverLibraryService.queryScreensaverLibrary(imei);
    }

    /***
     * @description 更新微聊联系人
     * @author cwj
     * @param [imei, vo, image]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/6/24 17:39
     **/
    @PostMapping("/{imei}/wechatContact/update")
    public ResponseMap updateWechatContact(@PathVariable("imei") String imei, @Validated DeviceWechatContactUpdateReqVO vo, MultipartFile image) throws IOException {
        return wechatContactService.updateWechatContact(imei,vo,image);
    }

    /**
     * @description 删除设备的微聊联系人
     * @author cwj
     * @param [imei, vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/6/25 9:05
     **/
    @PostMapping("/{imei}/wechatContact/delete")
    public ResponseMap deleteWechatContact(@PathVariable("imei") String imei, @Validated DeviceWechatContactDelReqVO vo) {
        return wechatContactService.deleteWechatContact(imei,vo);
    }

    
    /**
     * @description 查询群聊微聊的联系人
     * @author cwj
     * @param [imei, vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/6/25 10:44
     **/
    @GetMapping("/{imei}/wechatContact/query")
    public ResponseMap queryWechatContact(@PathVariable("imei") String imei, @Validated DeviceWechatContactQueryReqVO vo) {
        return wechatContactService.queryWechatContact(imei,vo);
    }
}
